package com.kaigejava.javanotebook.threaddemo.ruturndemo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author kaigejava
 * 线程实现第二分类：带有返回值的
 * 方式一：实现 Callable接口
 */
public class CallableDemo implements Callable {

    @Override
    public Object call() throws Exception {
        StringBuilder sb = new StringBuilder();
        sb.append("凯哥");
        sb.append("Java");
        sb.append("===>");
        sb.append("【kaigejava】");
        return sb.toString();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask(new CallableDemo());
        new Thread(task).run();
        System.out.println("从线程中获取到的返回信息是:"+task.get());
    }
}
